<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 计算右侧小于当前元素的个数 -->
    <script>
      var countSmaller = nums => {
        let counts = new Array(nums.length)
        for (let i = 0; i < nums.length; i++) {
          let count = 0
          for (let j = i + 1; j < nums.length; j++) {
            if (nums[j] < nums[i]) {
              count++
            }
          }
          counts[i] = count
        }
        return counts
      }
      console.log(countSmaller([5, 2, 6, 1]))
    </script>
  </body>
</html>
